<template>
  <div class="index">
    <h2
      style="
        font-weight: 700;
        font-style: normal;
        font-size: 24px;
        color: #344563;
      "
    >
      入库管理
    </h2>
    <div class="monter">
      <table>
        <tr>
          <td>
            <div class="block">
              <span class="demonstration">开始时间：</span>
              <el-date-picker
                v-model="valuedate"
                type="date"
                placeholder="选择日期"
              ></el-date-picker>
            </div>
          </td>
          <td>
            <div class="block">
              <span class="demonstration">结束时间：</span>
              <el-date-picker
                v-model="valueendata"
                type="date"
                placeholder="选择日期"
              ></el-date-picker>
            </div>
          </td>
          <td>
            <el-button
              type="primary"
              icon="el-icon-zoom-in"
              size="mediu"
              @click="chaxun"
              >查询</el-button
            >
            <el-button
              type="success"
              icon="el-icon-plus"
              size="mediu"
              @click="addruku"
              >新增</el-button
            >
            <el-button
              type="info"
              icon="el-icon-refresh-right"
              size="mediu"
              @click="congz"
              >重置</el-button
            >
          </td>
        </tr>
        <tr>
          <td>
            <div class="block">
              <span class="demonstration">审核状态: &nbsp;</span>
              <el-select v-model="value" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <!--  -->
            </div>
          </td>
          <td class="td-input">
            <div class="sl">搜索：</div>
            <el-input v-model="input3" placeholder="请输入内容"></el-input>
          </td>
        </tr>
      </table>
    </div>
    <!-- 下面渲染阶段 -->
    <div class="last">
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="storageDate" label="入库时间"></el-table-column>
        <el-table-column prop="storageId" label="入库单"></el-table-column>

        <el-table-column prop="storageMan" label="制单人"></el-table-column>
        <el-table-column prop="auditTybe" label="审核状态"></el-table-column>
        <el-table-column prop="auditMan" label="审核人"></el-table-column>
        <el-table-column prop="caozuo" label="操作">
          <template slot-scope="scope">
            <el-button
              class="edit_btn"
              type="primary"
              size="small"
              icon="el-icon-edit"
              @click="lookku(scope.row.storageId)"
            ></el-button>
            <el-button
              class="del_btn"
              type="primary"
              size="small"
              icon="el-icon-delete"
              @click="deleku(scope.row.storageId)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="nex">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage3"
        :page-size="5"
        layout="prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <span class="demonstration">直接前往</span>
    </div>
    <!-- 查看的弹框 -->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div>
        <el-input
          v-model="inp1"
          placeholder="修改入库单号"
          :disabled="true"
        ></el-input>
      </div>
      <div>
        <el-input v-model="inp2" placeholder="修改单据类型"></el-input>
      </div>
      <div>
        <el-input
          v-model="inp3"
          placeholder="修改制单人"
          :disabled="true"
        ></el-input>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="surexiu">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { time, error } from "highcharts";
export default {
  data() {
    return {
      input3: "",
      valuedate: "",
      valueendata: "",
      value: "",

      page: 1,
      limit: 5,
      //total是页码的总数
      total: 1,
      checked: false,
      dialogVisible: false,
      currentPage3: 1,
      inp1: "",
      inp2: "",
      inp3: "",
      options: [
        {
          value: "待审核",
          label: "待审核",
        },
        {
          value: "审核通过",
          label: "审核通过",
        },
        {
          value: "审核不通过",
          label: "审核不通过",
        },
      ],
      tableData: [
        {
          storageDate: "2016-05-04",
          storageId: "1234561",
          storagetybe: "验收入库单",
          storageMan: "代蒙A",
          auditTybe: "待审核",
          auditMan: "代蒙B",
        },
      ],
    };
  },
  methods: {
    switchDate: function (sj) {
      var now = new Date(sj);
      var year = now.getFullYear();
      var month = now.getMonth() + 1;
      var date = now.getDate();
      return year + "-" + month + "-" + date;
    },
    congz: function () {
      this.page = 1;
      this.allxuan(this.page);
      this.currentPage3 = 1;
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    addruku: function () {
      this.$router.push("/home/AddRkd");
    },
    handleChange(value) {
      console.log(value);
    },
    handleChange1(value) {
      console.log(value);
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      //点击之后，回调多少页
      this.page = val;
      this.allxuan();
      console.log(this.page);
    },
    switchDate: function (sj) {
      var now = new Date(sj);
      var year = now.getFullYear();
      var month = now.getMonth() + 1;
      var date = now.getDate();
      return year + "-" + month + "-" + date;
    },
    //渲染全部页面的方法
    allxuan() {
      this.tableData = [];

      let k = 0;
      console.log(this.value);
      switch (this.value) {
        case "待审核":
          k = "1";
          break;
        case "审核通过":
          k = "2";
          break;
        case "审核不通过":
          k = "3";
          break;
        default:
          k = 0;
          break;
      }
      console.log(k);

      this.$axios({
        url: "/wReceiptManagement/list",
        method: "post",
        data: {
          auditStatus: k == "" ? null : k,
          receiptNo: this.input3.length ? this.input3 : null,
          endTime: this.switchDate(this.valueendata)
            ? null
            : this.switchDate(this.valueendata),
          limit: 5,
          page: this.page,
          startTime: this.switchDate(this.valuedate)
            ? null
            : this.switchDate(this.valuedate),
        },
      }).then((res) => {
        this.total = res.data.total;
        console.log(res.data);
        this.tableData = [];
        for (let i = 0; i < res.data.data.length; i++) {
          //把数据给tem
          let so = {
            storageDate: "",
            storageId: "",
            storagetybe: "",
            storageMan: "",
            auditTybe: "",
            auditMan: "",
          };
          so.storageDate = this.switchDate(res.data.data[i].receiptDate);
          so.storageId = res.data.data[i].receiptNo;
          so.storageMan = res.data.data[i].preparedBy;
          so.auditTybe = res.data.data[i].auditStatus;
          so.auditMan = res.data.data[i].reviewedBy;

          this.tableData.push(so);
        }
      });
    },
    //查询
    chaxun() {
      //把所需要的东西传入过去
      this.page = 1;
      this.allxuan();
    },
    //查看内容
    lookku(e) {
      console.log(e);
      //e为查询想看的条件
      this.$axios({
        url: "/wReceiptManagement/list",
        method: "post",
        data: {
          auditStatus: null,
          endTime: "",
          limit: 5,
          page: 1,
          receiptNo: e,
          startTime: "",
        },
      }).then((res) => {
        console.log(res);
        this.inp3 = res.data.data[0].preparedBy;
        this.inp2 = res.data.data[0].auditStatus;
        this.inp1 = res.data.data[0].receiptNo;
      });
      this.dialogVisible = true;
    },
    //确认修改内容
    surexiu() {
      this.$axios({
        url: "/wReceiptManagement/update",
        method: "put",
        data: {
          auditStatus: this.inp2,
          receiptNo: this.inp1,
        },
      }).then((res) => {
        console.log(res);
        this.allxuan();
        this.dialogVisible = false;
      });
    },
    //删除
    deleku(ev) {
      //把这个传过去，删除
      console.log(new Number(ev));
      this.$axios({
        url: "/wReceiptManagement/delete",
        method: "delete",
        params: {
          receiptNo: ev,
        },
      }).then((res) => {
        console.log(res);
        this.allxuan();
      });
    },
    //重置
    congz() {
      (this.valueendata = ""), (this.valuedate = ""), (this.page = 1);
      this.input3 = "";
      this.value = "";
      this.allxuan();
    },
  },
  pickerOptions: {
    disabledDate(time) {
      return time.getTime() > Date.now();
    },
  },
  mounted: function () {
    this.page = 1;
    this.allxuan();
  },
};
</script>

<style  scoped>
.nex {
  margin-top: 30px;
  display: flex;
  justify-content: right;
  margin-right: 20px;
  align-items: center;
}

table {
  width: 100%;
  margin: 40px;
}
.index table .el-input__inner {
  width: 100px;
}
.index {
  padding: 30px;
}
tr {
  margin-top: 40px;
}
td {
  width: 168px;
}
.ne {
  height: 50px;
  margin: 0 auto;
}
.ne .el-pagination {
  text-align: center;
  margin: 0 auto;
  margin-top: 30px;
}
.ne .el-button {
  float: left;
}
.td-input {
  display: flex;
  align-items: center;
}
.td-input,
.el-input > .el-input__inner {
  width: 260px;
}
.sl {
  width: 65px;
  margin-right: 10px;
}
.el-main .content-box .index .monter > table tr {
  line-height: 50px;
  width: 600px;
}
.demonstration {
  margin-right: 5px;
}
.del_btn {
  font-size: 14px;
  color: #ffc5c5;
  background: #fef3f3;
  border-color: #fef3f3;
}

.edit_btn {
  font-size: 14px;
  color: #5fa4e2;
  background: #eef6fc;
  border-color: #eef6fc;
}
</style>